package com.turing.data.scripts.contract.filter

import com.turing.common.util.FileUtils
import com.turing.common.util.StringUtils
import com.turing.data.engine.utils.ScriptsUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO

/**
 * 场景：资产管理合同-v3.0
 * 版本：Version 3.0
 * 要素名称：预警线数额
 */

class WarningLineNumber_30194_10_filter {

    static List< TaskElementVO.DrawResultVO > doConvert(DependParamsVO dependParams){

        def Regex_HAS = /.*预警线.*/

        def textPathMap = dependParams.textPathMap

        List<TaskElementVO.DrawResultVO > trueValueSet = new ArrayList<>()
        List<TaskElementVO.DrawResultVO > resultVOs = ScriptsUtils.tryInitResult(dependParams)
        if (resultVOs!=null && resultVOs.size()>0) {
            for (int i = 0; i < resultVOs.size(); i++) {
                if(StringUtils.isEmpty(resultVOs.get(i).childTaskSn)){
                    continue
                }

                def rawPath = textPathMap.get(resultVOs.get(i).childTaskSn)
                def rawText = FileUtils.loadJson(rawPath)
                def expandOffset = 0
                def start = resultVOs.get(i).start
                def end = resultVOs.get(i).end
                while( expandOffset < 100 && start > expandOffset  ){
                    def expandStr = rawText.substring( start - expandOffset,end + expandOffset )

                    if( expandStr =~ Regex_HAS ){
                        trueValueSet.add( resultVOs.get(i) )
                        return trueValueSet
                    }
                    expandOffset ++
                }
            }
        }


        return  resultVOs
    }
}
